<template>
	<div class="myAchievements">
		<div class="classIndex_h">
			<span v-if="roleBaseid(4)">我的成绩</span>
			<span v-if="roleBaseid(5)">孩子成绩</span>
		</div>
		<!--  -->
		<div class="classNotice_search myAchievements-h  clear">
			<div class="achievement_type fl">
				<template v-if="roleBaseid(5)">
					<router-link :to="{path: '/class/achieve/index', query: {id: path}}">
						孩子成长
					</router-link>
					<router-link :to="{path: '/class/achieve/growth', query:{id: path}}">
						孩子成绩
					</router-link>
				</template>
				<template v-else>
					<router-link :to="{path: '/class/achieve/index', query: {id: path}}">
						我的成长
					</router-link>
					<router-link :to="{path: '/class/achieve/growth', query:{id: path}}">
						我的成绩
					</router-link>
				</template>
			</div>
		</div>
		<!--  -->
		<div class="myAchievements-batle" v-for="(item, index) in examResults" :key="index">
			<h3>{{item.testname}}</h3>
			<table>
				<thead>
					<tr>
						<th>试卷名</th>
						<th>占比</th>
						<th>得分</th>
						<th>总分</th>
						<th>班级平均分</th>
						<th>排名</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>{{item.testname}}</td>
						<td>{{item.percent}}</td>
						<td>{{item.score}}</td>
						<td>{{item.sum_score}}</td>
						<td>{{item.ping_score}}</td>
						<td>{{item.rank}}</td>
					</tr>
				</tbody>
			</table>
			<div class="myAchievements-ej">
				<div>
					<img v-if="item._pingscore > 0" src="../../../public/images/Group7.png">
					<img v-else src="../../../public/images/Group8.png">
					<template>
						<span>
							<template>
								<i v-if="item._pingscore < 0">总分低于平均分{{Math.abs(parseInt(item._pingscore))}}分，</i>
								<i v-else>总分高于平均分{{Math.abs(parseInt(item._pingscore))}}分，</i>
							</template>
							<template>
								<i v-if="item._score < 0">比上次退步 {{Math.abs(parseInt(item._score))}} 分，</i>
								<i v-else>比上次进步 {{Math.abs(parseInt(item._score))}} 分</i>
							</template>
							<template>
								<i v-if="item._rank < 0">排名下降 {{Math.abs(parseInt(item._rank))}} 位</i>
								<i v-else>排名上升 {{Math.abs(parseInt(item._rank))}} 位</i>
							</template>
						</span>
					</template>
				</div>
				<div>
					<span :title='item.create_name'>{{item.create_name}}</span>老师于{{item.create_time.substring(0,4)}}年{{item.create_time.substring(5,7)}}月{{item.create_time.substring(8,10)}}日发布
				</div>
			</div>
		</div>
		<div class="dependent" v-if="placeholder">
			<i class="ipm image_nofound"></i>
			<p>
				还没发现任何相关的内容哦~
			</p>
		</div>
	</div>
</template>
<script>
export default {
	data() {
		return {
			path: this.$route.query.id,
			examResults: [],
			placeholder: false,
			identityVal: sessionStorage.getItem('parent_child_id') ? sessionStorage.getItem('parent_child_id') : this.$g.user_id, //缓存孩子id
			role: this.roleBaseid(5),
		}
	},

	created() {
		// this.getExamResults()
	},
	watch: {


		'$store.state.changData': {
			handler(val, newval) {
				this.path = sessionStorage.getItem('classId')
				this.identityVal = sessionStorage.getItem('parent_child_id') ? sessionStorage.getItem('parent_child_id') : this.$g.user_id; //缓存孩子id
				this.getExamResults()
			},
			immediate: true
		}
	},
	computed: {
		changData() {
			return deep_clone(this.$store.state.changData);
		},
	},
	methods: {
		//获取科目
		getExamResults() {
			let success = res => {
				let data = res.data;
				this.examResults = data.data;

				this.examResults.length === 0 ?
					this.placeholder = true :
					this.placeholder = false
			};

			let params = {
				studentid: this.$g.user_id,
				classid: this.path,
				order: 'time'
			}
			
			if (this.role) {
				params.studentid = this.identityVal
				this.$ajax.get('api/statistics/student_grade_static_list', { params, func: { success: success} })
			} else {
				this.$ajax.get('api/statistics/student_grade_static_list', { params, func: { success: success} })
			}

		},
	}
}
</script>